package com.cmict.data.bpm.dal.mysql.task;

import com.cmict.data.framework.common.pojo.PageResult;
import com.cmict.data.framework.mybatis.core.mapper.BaseMapperX;
import com.cmict.data.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cmict.data.bpm.controller.admin.task.vo.task.message.TaskMessageExportReqVO;
import com.cmict.data.bpm.controller.admin.task.vo.task.message.TaskMessagePageReqVO;
import com.cmict.data.bpm.dal.dataobject.task.TaskMessageDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 流程消息 Mapper
 *
 * @author liutao
 */
@Mapper
public interface TaskMessageMapper extends BaseMapperX<TaskMessageDO> {

    default PageResult<TaskMessageDO> selectPage(TaskMessagePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TaskMessageDO>()
                .eqIfPresent(TaskMessageDO::getTemplateId, reqVO.getTemplateId())
                .eqIfPresent(TaskMessageDO::getType, reqVO.getType())
                .eqIfPresent(TaskMessageDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(TaskMessageDO::getTaskId, reqVO.getTaskId())
                .likeIfPresent(TaskMessageDO::getTaskName, reqVO.getTaskName())
                .eqIfPresent(TaskMessageDO::getRuleType, reqVO.getRuleType())
                .eqIfPresent(TaskMessageDO::getOptions, reqVO.getOptions())
                .betweenIfPresent(TaskMessageDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(TaskMessageDO::getId));
    }

    default List<TaskMessageDO> selectList(TaskMessageExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<TaskMessageDO>()
                .eqIfPresent(TaskMessageDO::getTemplateId, reqVO.getTemplateId())
                .eqIfPresent(TaskMessageDO::getType, reqVO.getType())
                .eqIfPresent(TaskMessageDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(TaskMessageDO::getTaskId, reqVO.getTaskId())
                .likeIfPresent(TaskMessageDO::getTaskName, reqVO.getTaskName())
                .eqIfPresent(TaskMessageDO::getRuleType, reqVO.getRuleType())
                .eqIfPresent(TaskMessageDO::getOptions, reqVO.getOptions())
                .betweenIfPresent(TaskMessageDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(TaskMessageDO::getId));
    }

}
